// src/composables/useUser.ts
import { reactive } from 'vue'
import { useRouter } from 'vue-router'
import myaxios from '@/auth/auth.service'
import { useAuthStore } from '@/stores/auth'
import {showToastMessage} from "@/utils/message"

export function useUser() {
  const router = useRouter()
  const authStore = useAuthStore()

  // 完全保持原有userInfo字段
  const userInfo = reactive(authStore.user)

  // 保持原有handleLogout函数不变
  const handleLogout = async () => {
    try {
      await myaxios.logout()
      router.push('/login')
      alert('退出成功！')
    } catch (error) {
      console.error('退出失败:', error)
      alert('退出失败，请检查网络')
    }
  }

  // 保持原有goBack函数不变
  const goBack = () => {
    console.log('返回上一页')
    router.go(-1)
  }
  const goHome = () => {
    router.push('/category')
  }
  return {
    userInfo,
    handleLogout,
    goBack,
    goHome
  }
}
